2
2
.
.
1
1
.
.
6
6
S
S
t
t
a
a
t
t
e
e
m
m
e
e
n
n
t
t
s
s
-
-
L
L
o
o
o
o
p
p
I
I
n
n
f
f
o
o
Loop Statements execute its Body multiple times (while condition is TRUE or while iterating through Elements)
for…in Statement iterates through Sequence or Array Elements and executes its Body for each Element.
while Statement executes its Body while condition is TRUE. Condition is checked at the beginning of Body
repeat...while Statement executes its Body while condition is TRUE. Condition is checked at the end of Body.
You can use
break Jump Statement to exit Loop Statement
continue Jump Statement to skip rest of the Body and continue with next iteration from the beginning of Body
for…in
//Iterate through Sequence Elements
for i in 1...5 {
print(i)
}
//Iterate through Array Elements
for person in ["John", "Lucy", "Bob"] {
print(person)
}
while
//Execute Body while i < 4. Check conditions at the begining of the Body.
var i = 0
while(i < 4) {
i = i + 1
print(i)
}
repeat ... while
//Execute Body while i < 4. Check conditions at the end of the Body.
var i = 0
repeat {
i = i + 1
print(i)
} while(i < 4)